找传奇、传世资源到传世资源站!

Indy10文件传输无过程(含服务器端以及客户端源码)

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

from clipboard
from clipboardunit server;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdCustomTCPServer, IdTCPServer, IdContext;type TForm_FileTransimision = class(TForm) Edit_path: TEdit; Button_selectPath: TButton; Button_start: TButton; Button_cancel: TButton; IdTCPServer1: TIdTCPServer; OpenDialog1: TOpenDialog; procedure Button_selectPathClick(Sender: TObject); procedure Button_startClick(Sender: TObject); procedure IdTCPServer1Execute(AContext: TIdContext); procedure Button_cancelClick(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form_FileTransimision: TForm_FileTransimision; AFileStream: TFileStream;implementation{$R *.dfm}procedure TForm_FileTransimision.Button_cancelClick(Sender: TObject);begin AFileStream.Free;end;procedure TForm_FileTransimision.Button_selectPathClick(Sender: TObject);begin if OpenDialog1.Execute then Edit_path.Text := OpenDialog1.FileName;end;procedure TForm_FileTransimision.Button_startClick(Sender: TObject);begin if not FileExists(Edit_path.Text) then //检测文件是否存在 begin Showmessage('文件不存在,请选择文件!'); exit; end; AFileStream := TFileStream.Create(Edit_path.Text, fmOpenRead);end;procedure TForm_FileTransimision.IdTCPServer1Execute(AContext: TIdContext);var cmd: string; //接收到客户端的字符串信息begin with AContext.Connection do //已经连街上的一个进程 begin cmd := UpperCase(IOHandler.ReadLn); //客户端发送的命令字符串 if cmd = 'BEGIN' then //开始传输 begin //告诉远程传输文件的大小和文件名 IOHandler.WriteLn(Format('%d|%s', [AFileStream.Size, ExtractFileName(Edit_path.Text)])); IOHandler.Write(AFileStream,AFileStream.Size); //Exit; end; if cmd = 'END' then begin //传输完成 AFileStream.Free; Exit; end; {if cmd = 'CANCEL' then begin //传输取消 //保持传输状态 Exit; end; } end;end;end.

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复